<template>
  <div class="mod-config">
    <div class="sql-box">
      <SqlEditor
        ref="sqleditor"
        :value="basicInfoForm.sqlMain"
        @changeTextarea="changeTextarea($event)"
      />
    </div>
    <el-button
      type="primary"
      size="small"
      class="sql-btn"
      @click="formaterSql(basicInfoForm.sqlMain)"
      >格式化sql</el-button
    >
    <el-button type="primary" size="small" class="sql-btn" @click="setValue"
      >保存</el-button
    >
  </div>
</template>

<script>
// import sqlFormatter from "./util/util";
import sqlFormatter from "sql-formatter";
import SqlEditor from "./SqlEditor";
export default {
  name: "app",
  components: {
    SqlEditor
  },
  data() {
    return {
      basicInfoForm: {
        sqlMain: `insert into scorebak select * from socre where neza='neza'
select *  into scorebak from score  where neza='neza'
SELECT column_name,column_name
FROM table_name
ORDER BY column_name,column_name ASC|DESC;`
      }
    };
  },
  methods: {
    changeTextarea(val) {
      this.$set(this.basicInfoForm, "sqlMain", val);
    },
    formaterSql() {
      let dom = this.$refs.sqleditor;
      dom.editor.setValue(sqlFormatter.format(dom.editor.getValue()));
    },
    setValue() {
      console.log(this.basicInfoForm);
    }
  }
};
</script>

<style>
.sql-box {
  width: 100%;
  border: 1px solid #ddd;
}
.sql-btn {
}
</style>
